package com.gang.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.io.*;
import java.util.ArrayList;
import java.util.UUID;

public class JSONUtil {
    public static UUID setJson(ArrayList list){
        String filePath = null;
            filePath = "H:\\tokenURI.json";
        UUID uuid = UUID.randomUUID();
        try {
            JSONObject jsonObject = JSON.parseObject(new FileInputStream(new File(filePath)), JSONObject.class);

            jsonObject.put("keyword",list.get(0));
            jsonObject.put("filepath",list.get(1));
            jsonObject.put("fileformat",list.get(2));
            jsonObject.put("msg",list.get(3));

            String pretty = JSON.toJSONString(jsonObject,
                    SerializerFeature.PrettyFormat,
                    SerializerFeature.WriteMapNullValue,
                    SerializerFeature.WriteDateUseDateFormat);

            BufferedWriter bw = new BufferedWriter(new FileWriter("H:\\"+uuid+".json"));
            bw.write(pretty);
            bw.flush();
            bw.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return uuid;
    }
}
